package ssl;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author kastillo
 */
public class clissl {
   public static void setProgramInfo(String store) {
//                System.setProperty("javax.net.ssl.keyStore",store);
//                System.setProperty("javax.net.ssl.keyStorePassword","123456");
                System.setProperty("javax.net.ssl.trustStore",store);
                System.setProperty("javax.net.ssl.trustStorePassword","123456");
             }
  public static void main(String[] arstring) {
   setProgramInfo("store");
   int port = 2500;
   String host = "localhost";
   String cadena;
   try{
       System.out.println("Inicio del cliente");
       SSLSocketFactory sslFact = (SSLSocketFactory)SSLSocketFactory.getDefault();
       SSLSocket s = (SSLSocket) sslFact.createSocket(host, port);
       // Definir stream de entrada y de salida a través
       // del socket SSL
       OutputStream os = s.getOutputStream();
       PrintWriter out = new PrintWriter(os, true);
       InputStream is = s.getInputStream();
       BufferedReader in = new BufferedReader(new InputStreamReader(is));
       // Escribir una línea en el socket SSL
       out.println("Esta es una linea que envia elcliente\r\n") ;
       // Leer desde el socket SSL y escribir en pantalla
       cadena = in.readLine();
       System.out.println("Se leyo del socket: " +cadena);
       // Cerrar el canal y el socket
       in.close();
       out.close();
       s.close();
   }catch(IOException e)
   {
       System.out.println("Error de lectura: " + e.getMessage());
   }
  }
}
